package eu.jpereira.trainings.designpatterns.creational.builder.xml;

import java.util.Iterator;

import eu.jpereira.trainings.designpatterns.creational.builder.ReportBodyBuilder;
import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;

public class XMLReportBodyBuilder extends ReportBodyBuilder {

	private XMLReportBody reportBody = new XMLReportBody();
	
	@Override
	public ReportBody getReportBody() {
		
		// Add customer info
		reportBody.putContent("<sale><customer><name>");
		reportBody.putContent(customerName);
		reportBody.putContent("</name><phone>");
		reportBody.putContent(phoneNumber);
		reportBody.putContent("</phone></customer>");
		
		// Add sale items info
		reportBody.putContent("<items>");
		Iterator<Item> it = soldItems.iterator();
		while ( it.hasNext() ) {
			Item item = it.next();
			reportBody.putContent("<item><name>");
			reportBody.putContent(item.name);
			reportBody.putContent("</name><quantity>");
			reportBody.putContent(item.quantity);
			reportBody.putContent("</quantity><price>");
			reportBody.putContent(item.price);
			reportBody.putContent("</price></item>");
		}
		reportBody.putContent("</items></sale>");
		
		return reportBody;
	}

}
